<?php
    // estilos -- ver por qué no puedo usar class con un css - otra clase debe estar bloqueandolo
    $tabla_orga_td = 'vertical-align: middle; border: none;';    

    // imagenes
    $prev_img = $this->Html->image("restaurante/ic_navegar_left.png", array("width" => "32px", "height" => "32px", "id" => "nav_icon_left"));    
    $next_img = $this->Html->image("restaurante/ic_navegar.png", array("width" => "32px", "height" => "32px", "id" => "nav_icon_right"));    
    $prev_img_disabled = $this->Html->image("restaurante/ic_nav_left_disabled.png", array("width" => "32px", "height" => "32px", "id" => "nav_icon_left_disabled"));    
    $next_img_disabled = $this->Html->image("restaurante/ic_navegar_disabled.png", array("width" => "32px", "height" => "32px", "id" => "nav_icon_right_disabled"));    

    $volver_img = $this->Html->image("restaurante/ic_back.png", array("id" => "back_icon"));    
    $nuevo_img = $this->Html->image("restaurante/ic_add.png", array("id" => "add_icon"));    
    $cancel_img = $this->Html->image("restaurante/ic_cancel.png", array("id" => "back_icon"));    
    $save_img = $this->Html->image("restaurante/ic_ok.png", array("id" => "save_icon"));    
    
    $editar_img = $this->Html->image("restaurante/doc_images.png", array("width" => "24px", "height" => "24px"));    
    
?>

<?php $options = array(1 => 'Cocina', 2 => 'Cafetería'); ?>    

<!--- MARCO DE LA PANTALLA ------>
<table><tr><td style="padding: 20px; background: white; border: none;">

<table>
    <tr>
        <td style="width: 15%; text-align:right; <?php echo $tabla_orga_td;?>"><?php echo $this->Html->image("restaurante/ic_resto.png", array("width" => "64px", "height" => "64px", "id" => "resto_icon"));?></td>
        <td style="width: 55%; text-align:left; <?php echo $tabla_orga_td;?>"><h1 class="titulo_ventana">MENU</h1></td>
        <td style="width: 30%; text-align:right; <?php echo $tabla_orga_td;?>">
            <table>
                <tr><td style="text-align:right; <?php echo $tabla_orga_td;?>"><?php echo 'Usuario: '.$nombre_usuario;?></td></tr>
                <tr><td style="text-align:right; <?php echo $tabla_orga_td;?>"><?php echo $this->Html->link('Cerrar sesión', array("controller"=>"users", "action"=>"logout"), array('title' => 'Cerrar sesión', 'escape' => false));?></td></tr>
            </table>
        </td>
    </tr>      
</table>
<hr>

<?php echo $this->Form->create('Menu', array('action'=>'/index','novalidate' => true)); ?>

<!--- CONTROLES Y BOTONERA FILTROS ------>
<table>
    <tr>
        <td style="width: 20%;<?php echo $tabla_orga_td;?>">
            <table>
                <td style="text-align:left; vertical-align: middle; <?php echo $tabla_orga_td;?>">
                    <?php echo $this->Form->label('categoria', 'Categoría<span style="color: black; "></span>'); ?></td>
                <tr><td style="<?php echo $tabla_orga_td;?>"><?php echo $this->Form->input('cat_cocina', array('checked' => true, 'label' => 'Cocina')); ?></td></tr>
                <tr><td style="<?php echo $tabla_orga_td;?>"><?php echo $this->Form->input('cat_cafeteria', array('checked' => true, 'label' => 'Cafetería')); ?></td></tr>
            </table>            
        </td>
        <td style="width: 20%;<?php echo $tabla_orga_td;?>"><?php echo $this->Form->input('filtro_rubro', array('label' => 'Rubro')); ?></td>
        <td style="width: 20%;<?php echo $tabla_orga_td;?>"><?php echo $this->Form->input('filtro_subrubro', array('label' => 'Subrubro')); ?></td>
        <td style="width: 10%;<?php echo $tabla_orga_td;?>"><?php echo $this->Form->input('filtro_codigo', array('label' => 'Código')); ?></td>
        <td style="width: 20%;<?php echo $tabla_orga_td;?>"><?php echo $this->Form->input('filtro_descripcion', array('label' => 'Descripción')); ?></td>
        <td style="width: 10%; text-align:right; <?php echo $tabla_orga_td;?>"><?php echo 'Buscar'; ?></td>
        <td style="width: 10%; text-align:left; <?php echo $tabla_orga_td;?>"><?php echo $this->Form->submit('restaurante/ic_search.png',array('class' => 'boton-buscar')); ?> </td>
        <td style="width: 10%; text-align:right; <?php echo $tabla_orga_td;?>"><?php echo 'Limpiar'; ?></td>
        <td style="width: 10%; text-align:left; <?php echo $tabla_orga_td;?>"><?php echo $this->Form->button('', array('type'=>'reset','class' => 'boton-limpiar')); ?></td>    
    </tr>        
</table>

<?php echo $this->Form->end(); ?>

<!--- GRILLA ------>
<table><tr>
        <?php 
            $cant_filas = 0;
            foreach ($menu_items as $menu_item): 
            if(($cant_filas == 0) || ($cant_filas == 10)) {
                echo '<td style="width: 45%; border:none; vertical-align:top;"><table>';
            }
            echo '<tr>';
                
            switch($menu_item['Corte']) {
            case 1: 
                echo '<td style="width:15%;"></td>';
                echo '<td style="width:70%;padding-left:0%;"><b>'.$menu_item['Descripcion'].'</b></td>';
                echo '<td style="width:15%;"></td>';                              
                break;
            case 2: 
                echo '<td style="width:15%;"></td>';
                echo '<td style="width:70%;padding-left:5%;"><b>'.$menu_item['Descripcion'].'</b></td>';
                echo '<td style="width:15%;"></td>';                              
                break;
            case 3: 
                echo '<td style="width:15%;"></td>';
                echo '<td style="width:70%;padding-left:10%;"><b>'.$menu_item['Descripcion'].'</b></td>';
                echo '<td style="width:15%;"></td>';                              
                break;
            case 4: 
                echo '<td style="width:15%;">'.$menu_item['Codigo'].'</td>';
                if($cargo_usuario == 4) {
                    echo '<td style="width:70%;padding-left:10%;">'.$this->Html->link($menu_item['Descripcion'], '/productos/editar/'.$menu_item['Id'], array('escape' => false)).'</td>';
                } else {
                    echo '<td style="width:70%;padding-left:10%;">'.$menu_item['Descripcion'].'</td>';
                }
                echo '<td style="width:15%;">$'.$menu_item['Precio'].'</td>';                              
                break;
            case 5: 
                echo '<td style="width:15%;"></td>';
                echo '<td style="width:70%;padding-left:15%;"><b>'.$menu_item['Descripcion'].'</b></td>';
                echo '<td></td>';                                
                break;
            case 6: 
                echo '<td style="width:15%;">'.$menu_item['Codigo'].'</td>';
                if($cargo_usuario == 4) {
                    echo '<td style="width:70%;padding-left:15%;">'.$this->Html->link($menu_item['Descripcion'], '/agregados/editar/'.$menu_item['Id'], array('escape' => false)).'</td>';
                } else {
                    echo '<td style="width:70%;padding-left:15%;">'.$menu_item['Descripcion'].'</td>';
                }
                echo '<td style="width:15%;">$'.$menu_item['Precio'].'</td>';                              
                break;
            }

            echo '</tr>';

            if($cant_filas == 9) {
                echo '</table></td><td style="width:10%;'.$tabla_orga_td.'"></td>';
            }

            $cant_filas++;
            endforeach; 
            
            // cierro tabla izquierda
            if($cant_filas < 9) { echo '</table></td><td style="width:10%;'.$tabla_orga_td.'"></td>'; }
            // abro la tabla derecha
            if($cant_filas < 10) { echo '<td style="width: 45%; border:none; vertical-align:top;"><table>'; }
            echo '</table></td>'; 
            
            
            ?>    

</tr></table>

    
<!--- PAGINADO ------>
<table>
    <tr>
        <td style="width: 10%; <?php echo $tabla_orga_td;?>"><?php  echo $this->Paginator->prev(!$this->Paginator->hasPrev() ? null : $prev_img, array('escape' => false), !$this->Paginator->hasPrev() ? $prev_img_disabled : null, array('class'=>'prev disabled','escape' => false));?></td>
        <td style="width: 10%; <?php echo $tabla_orga_td;?>"><?php  echo $this->Paginator->next(!$this->Paginator->hasNext() ? null : $next_img, array('escape' => false), !$this->Paginator->hasNext() ? $next_img_disabled : null, array('class'=>'next disabled','escape' => false));?></td>
        <td style="width: 80%; <?php echo $tabla_orga_td;?>"></td>
    </tr>
</table>

<!--- BOTONERA ------->
<table>
    <tr>
        <td style="width: 10%; text-align:right; <?php echo $tabla_orga_td;?>"><?php echo 'Volver'; ?></td>
        <td style="width: 10%; text-align:left; <?php echo $tabla_orga_td;?>"><?php echo $this->Html->link($volver_img, array("controller"=>"mainmenus", "action"=>"index"), array('class' => 'button', 'title' => 'Volver', 'escape' => false));?></td>
        <td style="width: 20%; <?php echo $tabla_orga_td;?>"></td>
        <td style="width: 10%; text-align:right; <?php echo $tabla_orga_td;?>"><?php if($cargo_usuario == 4) echo 'Nuevo Producto'; ?></td>
        <td style="width: 10%; text-align:left; <?php echo $tabla_orga_td;?>"><?php if($cargo_usuario == 4) echo $this->Html->link($nuevo_img, array("controller"=>"productos", "action"=>"nuevo"), array('class' => 'button', 'title' => 'Nuevo', 'escape' => false));?></td>
        <td style="width: 10%; <?php echo $tabla_orga_td;?>"></td>
        <td style="width: 10%; text-align:right; <?php echo $tabla_orga_td;?>"><?php if($cargo_usuario == 4) echo 'Nuevo Agregado'; ?></td>
        <td style="width: 10%; text-align:left; <?php echo $tabla_orga_td;?>"><?php if($cargo_usuario == 4) echo $this->Html->link($nuevo_img, array("controller"=>"agregados", "action"=>"nuevo"), array('class' => 'button', 'title' => 'Nuevo', 'escape' => false));?></td>
    </tr>
</table>

<!-- overlayed element -->
<div id="dialogModal">
     <!-- the external content is loaded inside this tag -->
     <div class="contentWrap"></div>
</div>

<?php //echo $this->Html->link(__('Nuevo producto', true), array("controller"=>"producto", "action"=>"nuevo"), array("class"=>"overlay", "title"=>'Nuevo producto'));?>

<!--- FIN MARCO DE LA PANTALLA ------>
</td></tr></table>

<script>
$(document).ready(function() {
    //prepare the dialog
    $( "#dialogModal" ).dialog({
        autoOpen: false,
        show: {
            effect: "blind",
            duration: 100
            },
        hide: {
            effect: "blind",
            duration: 100
            },
        modal: true
        });
    //respond to click event on anything with 'overlay' class
    $(".overlay").click(function(event){
        event.preventDefault();
        $('#contentWrap').load($(this).attr("href"));  //load content from href of link
        $('#dialogModal').dialog('option', 'title', $(this).attr("title"));  //make dialog title that of link
        $('#dialogModal').dialog('open');  //open the dialog
        });
    });
</script>

